#include "tcpkernel.h"

tcpkernel::tcpkernel(QObject *parent)
    : QObject{parent}
{

    m_pTCPNet=new TCPClient(this);

}

tcpkernel::~tcpkernel()
{
    delete m_pTCPNet;
   
}

bool tcpkernel::open(const char *szip, short sport)
{
    if(!m_pTCPNet->connectServer(szip,sport))
        return false;
    return true;
}

void tcpkernel::close(const char *szerr)
{
    m_pTCPNet->disconnectServer(szerr);

}

bool tcpkernel::sendData(const char *szbuf, int nlen)
{
    if(!m_pTCPNet->sendData(szbuf,nlen))
        return false;
    return true;
}

void tcpkernel::dealDate(const char *szbuf)
{
    switch(*szbuf){
    case _default_procotol_register_rs:
        emit signal_register((STRU_REGISTER_RS*)szbuf);
        break;
    case _default_procotol_login_rs:
        emit signal_login((STRU_LOGIN_RS*)szbuf);
        break;
    case _default_procotol_getfilelist_rs:
        emit signal_getfilelist((STRU_GETFILELIST_RS*)szbuf);
        break;
    case _default_procotol_uploadfileinfo_rs:
        emit signal_uploadfile((STRU_UPLOADFILEINFO_RS*)szbuf);
        break;
    case _default_procotol_downloadfileinfo_rs:
        emit signal_downloadfileinfo((STRU_DOWNLOADFILEINFO_RS*)szbuf);
        break;
    case _default_procotol_downloadfileblock_rs:
        emit signal_downloadfileblock((STRU_DOWNLOADFILEBLOCK_RS*)szbuf);
        break;
    case _default_procotol_deletefile_rs:
        emit signal_deletefile((STRU_DELETEFILE_RS*)szbuf);
        break;
    case _default_procotol_searchfile_rs:
        emit signal_searchfile((STRU_SEARCHFILE_RS*)szbuf);
        break;
    case _default_procotol_rename_rs:
        emit signal_rename((STRU_RENAME_RS*)szbuf);

    default:
        break;
    }
}
